<!--
 * @Author: JunyaoPan
 * @Date: 2021-09-26 10:13:33
 * @LastEditors: JunyaoPan
 * @LastEditTime: 2021-10-14 16:33:22
 * @Description: 
-->
<template>
  <div class="search">
    <!-- 头部 -->
    <Header></Header>
    <!-- 内容 -->
    <div class="content">
      <div class="content_left">
        <div>搜索结果</div>
      </div>
      <div class="content_right">
        <!-- 标题 -->
        <div
          class="content_right_top"
          v-for="item in list.slice(0, 1)"
          :key="item.id"
        >
          <div class="content_right_title">搜索结果</div>
          <div>
            当前位置 ·
            <span @click="toHome">首页 ·</span>
            搜索结果
          </div>
        </div>
        <!-- 列表 -->
        <div class="content_right_center">
          <ul v-for="item in list" :key="item.id">
            <li>
              <span style="float: left">{{ item.title }}</span>
              <span style="float: right">{{ item.publishTime | fmtDate }}</span>
            </li>
          </ul>
        </div>
      </div>
      <!-- 分页 -->
      <div class="content_right_bottom">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[8, 15, 30, 40]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
        <!-- :hide-on-single-page='true' -->
      </div>
    </div>

    <!-- 脚注 -->
    <Footer></Footer>
  </div>
</template>

<script>
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import { get } from "../utils/request";
export default {
  data() {
    return {
      list: [],
      currentPage: 1,
      pageSize: 8,
      total: 0,
    };
  },
  methods: {
    toHome() {
      this.$router.push({
        path: "/",
      });
    },
    async getList() {
      let data1 = {
        page: this.currentPage,
        pageSize: this.pageSize,
        title: this.$route.query.search,
      };
      let res = await get("/index/article/pageQuery", data1);
      console.log(res, "res");
      console.log(data1, "data1");
      this.list = res.data.list;
      this.total = res.data.total;
    },
    // 页面跳转
    handleSizeChange(val) {
      // val选择每页展示的条数
      // 将每页要展示的数据的条数进行更新
      this.pageSize = val;
      // 将当前的页数 重置到第一页
      this.currentPage = 1;
      console.log("val", val);
    },
    // 监听当前页码变化
    handleCurrentChange(val) {
      // 将当前页数与分页插件动态点击控制页数相绑定
      this.currentPage = val;
      // 重新调用获取所有数据的方法
      this.getList();
    },
  },
  components: { Header, Footer },
  created() {
    this.getList();
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0 auto;
  padding: 0;
  font-family: 宋体;
}
.content {
  width: 1100px;
  height: 450px;
  font-family: 宋体;
  margin: 30px auto;
  display: flex;
  .content_left {
    width: 250px;
    height: 500px;
    margin-right: 30px;
    div {
      height: 50px;
      line-height: 50px;
      background-color: #005825;
      color: white;
      text-align: center;
      font-weight: 800;
      font-size: 25px;
    }
  }
  .content_right {
    width: 820px;
    position: relative;
  }
  .content_right_top {
    border-bottom: 3px solid #005825;
    margin-bottom: 5px;
    height: 50px;
    color: #005825;
    line-height: 50px;
    div {
      font-size: 16px;
      float: right;
      padding: 0 10px;
    }
    .content_right_title {
      font-size: 28px;
      float: left;
    }
  }
  .content_right_center {
    width: 820px;
    font-size: 17px;
    li {
      height: 40px;
      line-height: 40px;
      border-bottom: 1px dotted rgba(170, 165, 165, 0.76);
      padding: 0 10px;
    }
  }
  .content_right_bottom {
    text-align: center;
    position: absolute;
    bottom: 30px;
    right: 15%;
  }
}
</style>
